import socket
import json


s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)


# 广播
def broadcast(block_data):
    """
    广播
    :param block_data:
    :return:
    """
    # 判断是否挖矿成功
    print("挖矿成功，正在进行广播...")
    s.sendto(bytes(json.dumps(block_data.get_block_info()), encoding='utf-8'), ('255.255.255.255', 22321))
